import createDvaApp from './createDvaApp';
import monitor from './monitor';
import { IBuildAppOptions, ICreateDvaAppInstance } from './interface';

export interface Window {
  __DVA_INSTANCE__: ICreateDvaAppInstance;
}

export function buildApp(options: IBuildAppOptions) {
  const { publicModels, loadModel, routes, selector, dvaOptions, hooks, root } = options;
  const dvaApp = createDvaApp({
    routes,
    publicModels,
    dvaOptions,
    loadModel,
    hooks,
    root,
  });
  window.__DVA_INSTANCE__ = dvaApp;
  monitor().boot();
  dvaApp.start(selector);
  return dvaApp;
}

export default buildApp;
